import pymysql
import re
from analysis.parse import dbutils


def bracup():
    internationalsize = ['90','85','80','75','70']
    chinasize = ['40','38','36','34','32']
    standsize = []
    bracup = ["A","B","C","D","E","F","G","a","b","c","d","e","f","g"]
    for size in internationalsize:
        for cup in bracup:
            standsize.append(size+cup)
            standsize.append(cup+size)
    # print(len(standsize))
    # print(standsize)
    return standsize


# 匹配罩杯的正则表达式
# [1-9]{1}[0-9]{1}[ABCDEFGabcdefg]{1}
# [ABCDEFGabcdefg]{1}[1-9]{1}[0-9]{1}
def judgesize(cup):
    par = re.compile("[ABCDEFGabcdefg]{1}")
    if len(par.findall(cup))!=0:
        flag = str(par.findall(cup)[0]).upper()
        if flag =='A':
            return 1
        if flag =='B':
            return 2
        if flag =='C':
            return 3
        if flag =='D':
            return 4
        if flag =='E':
            return 5
        if flag =='F':
            return 6
        if flag =='G':
            return 7
    else:
        return 0




if __name__ == '__main__':

    standsize = bracup()
    par1 = re.compile("[1-9]{1}[0-9]{1}[ABCDEFGabcdefg]{1}")
    par2 = re.compile('[ABCDEFGabcdefg]{1}[1-9]{1}[0-9]{1}')

    par3 = re.compile("[ABCDEFGabcdefg]{1}")

    for data in dbutils.get_areacup():
        area = data['area']

        res1 = par1.findall(data['cup'])
        res2 = par2.findall(data['cup'])

        cup = ""
        size = 0

        if len(res1)!=0:
            for i in res1:
                if i in standsize:
                    cup = str(i).upper()
                    size = judgesize(cup)
                    dbutils.save_clean_data(area,cup,size)
        elif len(res2)!=0:
            for j in res2:
                if j in standsize:
                    cup = str(j).upper()
                    size = judgesize(cup)
                    dbutils.save_clean_data(area,cup,size)
        else:
            dbutils.save_dirty_data(data['area'],data['cup'])

















